#include <jni.h>
#include "com_example_chendong_hellondk_Native.h"
#include "source.h"
#include "my_log.h"

JNIEXPORT jstring JNICALL Java_com_example_chendong_hellondk_Native_stringFromJNI
        (JNIEnv *env, jclass j){
    return  env->NewStringUTF(getString());
}

JNIEXPORT void JNICALL Java_com_example_chendong_hellondk_Native_dosomething
        (JNIEnv *env,jclass jc, jstring s){
    //调用java方法
    jclass  jclass1 = NULL;
    jmethodID id = NULL;
    jmethodID oid = NULL;
    jobject o = NULL;
    jclass1 = env->FindClass("com/example/chendong/hellondk/Native");
    if(jclass1==NULL){
        LOGE("can not find class");
        return;
    }
    oid = env->GetMethodID(jclass1,"<init>","()V");
    if(oid==NULL){
        LOGE("can not find class init method");
        return;
    }
    o = env->NewObject(jclass1,oid);
    if(o==NULL){
        LOGE("can not new class");
        return;
    }
    id = env->GetMethodID(jclass1,"doInJavaMethod","()V");
    if(id == NULL){
        LOGE("can not find method");
        return;
    }
    env->CallVoidMethod(o,id);
    env->DeleteLocalRef(jclass1);
    env->DeleteLocalRef(o);
//    spendStr(env,s);
}